﻿package kizzo.utils 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	/**
	 * ...
	 * @author 
	 */
		
	 
	public class CompoundEventDispatcher extends EventDispatcher	
	{		
		private var events_to_complete:int;
		
		
		
		public function CompoundEventDispatcher() 
		{
			this.events_to_complete = 0;
		}
		
		
		public function add(dispatcher:EventDispatcher, type:String):void
		{
			dispatcher.addEventListener(type, event_hnd);
			this.events_to_complete ++;
		}
		
		
		private function event_hnd(e:Event):void
		{
			this.events_to_complete --;
			if (this.events_to_complete == 0)
				dispatchEvent(new Event(Event.COMPLETE));
		}
		
	}
	
}